package com.example.exception;

import com.example.VO.BaseResultVO;
import com.example.VO.ErrorResult;
import org.apache.log4j.Logger;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by ykbboom on 2017/2/23.
 */
@ControllerAdvice
public class MyExceptionController {
    private static final Logger logger = Logger.getLogger(MyExceptionController.class);
    /**
     * 控制增强，异常捕捉
     * */
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public BaseResultVO handleException(Exception e){
        logger.error(e.getMessage(),e);
        ErrorResult errorResult = new ErrorResult(1000,e.getMessage());
        BaseResultVO baseResultVO = new BaseResultVO(errorResult,BaseResultVO.RESULT_CODE_FAIL,"服务器未知异常");
        return baseResultVO;
    }
}
